package com.ServiceImpl;

import com.Service.UserService;
import com.dao.UserDao;
import com.pojo.User;

import java.util.List;

public class UserServiceImpl implements UserService {

    @Override
    public User  getUserByUsernameAndPassword(String username, String password) {
        User user = UserDao.getUserByUsernameAndPassword(username,password);
        return user;
    }

    @Override
    public boolean login(String username, String password) {

        List<User> users = UserDao.getUserList();
        User user=new User();
        if (users.size()==0){
            user.setId("101");
        }else {
            user.setId((Integer.parseInt(users.get(users.size()-1).getId())+1)+"");
        }
        user.setName(username);
        user.setPassword(password);
        user.setAdmin(false);
        Object[] userOB={user.getId(),user.getName(),user.getPassword(),user.isAdmin()};
        boolean b = UserDao.addUser(userOB);
        return b;
    }


}
